package starlingui.component
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.filters.DropShadowFilter;
	import flash.geom.Matrix;
	import flash.geom.Point;
	
	import starling.display.Image;
	import starling.textures.Texture;
	
	public class TopList extends Image
	{
		public static var shader:BitmapData;
		
		private var size:int=20;
		private var top:int;
		private var shape:Shape;
		public function TopList()
		{
			super(Texture.empty());	
			
			top=Math.sqrt(Math.pow(size*1.5,2)-Math.pow(size,2));
			
			shape=new  Shape();
			
			var f:DropShadowFilter=new DropShadowFilter();
			f.angle=90;
			f.blurX=f.blurY=15;
			f.color=0x333333;
			f.distance=1;
			f.inner=true;
			shape.filters=[f];
			
		
		}
		
		public function show(w:int,h:int,x:int):void{
			var g:Graphics=shape.graphics;
			g.clear();
			g.beginBitmapFill(shader,null,true,false);
			g.drawRect(0,0,w,h);
			
			var left:int=x-size;
			var right:int=x+size;
			
			g.moveTo(left,0);
			g.lineTo(x,-top);
			g.lineTo(right,0);
			g.lineTo(left,0);
			g.endFill();
			
		
			
			var matrix:Matrix=new Matrix();
			matrix.translate(0,top);
			var bmd:BitmapData=new BitmapData(shape.width,shape.height,true,0);
			bmd.draw(shape,matrix);
			
			texture=Texture.fromBitmapData(bmd,false);
			readjustSize();
		}
		
		override public function set y(value:Number):void{
			value-=top;
			super.y=value;
		}
	}
}